/**
 * 软件下载的JS方法
 */
XF.Soft = new function(){
	this.init = function(){
		
		/*$("input[name=multipartFile]").bind("change",function(){
			var fileName = $("input[name=multipartFile]").val();
			if($("input[name=name]").val()==""){
				$("input[name=name]").val(fileName);
			}
		});*/
		
	};
	
	this.init_css = function(){
	    $(".oaTable table.tableList tbody tr:not('#tableHeader')").hover(
            function () {
                $(this).addClass("hover");
            }, function () {
                $(this).removeClass("hover");
            }
        );
	};
	
	this.listSoft = function(){
		XF.lightSideBar('softList');
		$.ajax({
			type:'post',
			url:global.contextPath + "/soft/softl",
			complete:function(xhr){
				xhr = xhr['responseText'];
				$('#softCenter').html(xhr);
			}
		});
	};
	
	this.manageSoft = function(){
		XF.lightSideBar('manageSoft');
		_search_listSoft(null, null, null, null, null, null);
	};
	
	this.deleteSoft = function(id){
		$.messager.confirm('提示',"确认删除吗？",function(r){
		    if (r){
				var url  = global.contextPath + "/soft/doDelete"
				$.ajax({
				  url: url,
				  type: "post",
				  data: {id:id},
				  complete: function(xhr){
					  xhr = xhr['responseText'];
					  xhr = new Function("return " + xhr);
					  xhr = xhr();
					  xhr = xhr['status'];
					  if(xhr=="SUCCESS"){
						  $.messager.show({
							title:'提示',
							msg:'删除成功',
							timeout:3000,
							showType:'slide'
						  });
						  _search_listSoft(null, null, null, null, null, null);
					  }else if(xhr=="FAILD"){
						  $.messager.show({
							title:'提示',
							msg:'删除失败',
							timeout:5000,
							showType:'slide'
						  });
					  }
				   }
				});
		    }
		});
	};

	/**
	 * 添加失败错误提示
	 */
	this.refreshAfterAddFaild = function(errorJson){
		if(typeof(errorJson)=="undefined")return;
		if(errorJson==null || errorJson=="")return;
		for(key in errorJson){
			var v = errorJson[key];
			var errorTip = $("#errorTip_"+key);
			errorTip.html(v);
			errorTip.show();
		}
	};
	
	this.editSoft = function(id){
		var url  = global.contextPath + "/soft/edit"
		$.ajax({
		  url: url,
		  type: "post",
		  data: {id:id},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  $("#softCenter").html(xhr);
		  }
		});
	};	
	
	this.uploadSoft = function(){
		XF.lightSideBar('uploadSoft');
		$.ajax({
			type:'post',
			url:global.contextPath + "/soft/add",
			complete:function(xhr){
				xhr = xhr['responseText'];
				$('#softCenter').html(xhr);
			}
		});		
	};
	
    this.listSoftSearch = function(orderByFields){
    	var orderByField = null;
    	var orderByMode = null;
		if(typeof(orderByFields)!="undefined"){
			orderByField = orderByFields;
		}
    	var td = $("th[orderByField="+orderByField+"]");
    	var orderByMode = td.find("span.px").attr("orderByMode");
    	
		var fileName = $("input[name=fileName]").val();
		var publicMan = $("input[name=publicMan]").val();
		var fileType = $("select[name=fileType]").val();
		var createDateBegin =  $('#createDateBegin').datebox('getValue');
		var createDateEnd =  $('#createDateEnd').datebox('getValue');
		_search_listSoft(orderByField,orderByMode,fileType,fileName,publicMan,createDateBegin,createDateEnd);
    	
    };
	
	
    this.searchSoft = function(fileType){
    	_soft_search('','',fileType);
    };
    
    this.searchByFileType = function(fileType){
    	_soft_search('','',fileType);
    	XF.Soft.searchByGroupAfterHanlder(fileType);
    };
    
    this.searchByGroupAfterHanlder = function(fileType){
    	var groups = $("#softTab li");
    	var targetGroup = $("#softTab li[group='"+fileType+"']");
    	groups.removeClass("focus");
    	targetGroup.addClass("focus");
    };

    /**
     * 公告详情页
     */
    this.detail = function(id){
    	config.notice_detail['args'] = [id];
    	SMT.ajax(config.notice_detail);
    };
    
    this.add = function(){
    	config.notice_detail['args'] = [''];
    	SMT.ajax(config.notice_add);
    };
    
    
    /**
     * 具体搜索方法实现
     */
    function _soft_search(orderByField,orderByMode,typeId){	    
    	config.soft_search['args'] = [orderByField,orderByMode,typeId];
    	SMT.xconfig.gvar.pageNum = '1';
    	SMT.ajax(config.soft_search);
    };
    
    function _search_listSoft(orderByField,orderByMode,fileType,fileName,publicMan,createDateBegin,createDateEnd){
    	config.listSoft_search['args']=[orderByField,orderByMode,fileType,fileName,publicMan,createDateBegin,createDateEnd];
    	SMT.xconfig.gvar.pageNum = '1';
    	SMT.ajax(config.listSoft_search);      	
    };
    
}();

config.soft_search = {
	url: ""+global.contextPath+"/soft/list",
    argsOrder: ['orderByField','orderByMode','typeId'],
    needVar: true,
    replaceExp: '#replaceDiv',
    callBack: function() {
    }		
};

config.listSoft_search = {
		url: ""+global.contextPath+"/soft/manageSoftList/",
	    argsOrder: ['orderByField','orderByMode','typeId','name','publicMan','createDateBegin','createDateEnd'],
	    needVar: true,
	    replaceExp: '#softCenter',
	    callBack: function() {
	    }
};
